package com.zjw.algorithm.ready1;

public class _最大子数组和 {


    public int maxSubArray(int[] nums) {

        if (nums == null || nums.length == 0) {
            return 0;
        }
        int[] dp = new int[nums.length];
        int maxValue = nums[0];
        dp[0] = nums[0];


        for (int i = 1; i < nums.length; i++) {
            dp[i] = Math.max(dp[i - 1] + nums[i], nums[i]);
            maxValue = Math.max(dp[i], maxValue);
        }

        return maxValue;

    }


}
